package com.sfc.spiderweb.util;

import org.springframework.util.StringUtils;

public class AmountUtils {

    public static String formatAmount(String amount) {
        if (StringUtils.isEmpty(amount)) {
            return "0";
        }
        amount = amount.replaceAll("[^0-9,\\.\\-]","");
        if (amount.length() > 2) {
            if (amount.substring(amount.length() - 3).contains(",")) {
                int i = amount.length() - amount.lastIndexOf(",") - 1;
                amount = amount.replaceAll("\\,|\\.", "");
                amount = amount.substring(0, amount.length() - i) + "." + amount.substring(amount.length() - i);
            } else {
                amount = amount.replaceAll("\\,", "");
            }
        }
        return amount;
    }

}
